<template>
  <el-dialog title="异常审核" :visible.sync="visible" width="640px" :close-on-click-modal="false">
    <div class="add-form">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="申请人">
          <span>{{ form.userName }}</span>
        </el-form-item>
        <el-form-item label="异常内容">
          <span>{{ form.abnormalContent }}</span>
        </el-form-item>
        <el-form-item label="审核状态" prop="status" :rules="[{ required: true, message: '请选择审核状态', trigger: 'change' }]">
          <XmSelect v-model="form.status" placeholder="审核状态" :options="transferAbnormalStatusList">
          </XmSelect>
        </el-form-item>
        <el-form-item label="审核信息" prop="content">
          <el-input type="textarea" v-model="form.processingResults" placeholder="请输入审核信息"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { disposeUnusual } from '@/api/transfer'
import { transferAbnormalStatusList } from '@/const'
export default {
  data() {
    return {
      transferAbnormalStatusList,
      visible: false,
      form: {
        id: '',
        status: '',
        processingResults: '',
      },
    }
  },
  methods: {
    show({ data }) {
      this.visible = true
      this.form = {
        ...data,
        status: data.status + '',
      }
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          disposeUnusual(this.getParams()).then(res => {
            if (res.data.code === 200) {
              this.$message({
                type: 'success',
                message: `提交成功！`
              })
              this.visible = false
              this.$emit('submit')
            } else {
              this.$message({
                type: 'error',
                message: res.data.msg
              })
            }
          })
        }
      })
    },
    getParams() {
      const params = {
        id: this.form.id,
        status: this.form.status,
        processingResults: this.form.processingResults,
      }
      return params
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
